#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Datetime: 2021/10/30 15:09
# @Author  : CHEN Wang
# @Site    :
# @File    : trading_data_weeks.py
# @Software: PyCharm

"""
脚本说明: 计算与价量相关衍生指标, 每三天计算一次
"""

import os
import pandas as pd
from quant_researcher.quant.project_tool.localize import DATA_DIR
from TQR_Applications.factor_database.crypto.trading_data_weeks import get_trading_data, all_ret_analysis
import os
import traceback
from task_monitor import task_to_db, send_error_to_email
from logger import logger
pd.options.mode.chained_assignment = None  # default='warn'


if __name__ == '__main__':
    file_path = os.path.join(DATA_DIR, f'trading_data')
    os.makedirs(file_path, exist_ok=True)

    # 计算市值占比数据，统计涨跌幅数据
    task_to_db(os.path.basename(__file__), 'get_trading_data', 0, 'BTC')
    try:
        get_trading_data(asset='BTC', start_date='2015-01-01', end_date=None)
    except Exception as e:
        msg = traceback.format_exc()
        logger.info(msg)
        send_error_to_email(script_name=os.path.basename(__file__), func_name="get_trading_data", message=msg)
        raise e
    task_to_db(os.path.basename(__file__), 'get_trading_data', 1, 'BTC')


    # 全市场收益率分析
    all_ret_analysis()